<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<base href="<%=basePath%>">
	<title>hr-m-s</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link rel="stylesheet" type="text/css" href="css/style.css" >
	<script type="text/javascript" src="<%=basePath%>js/jquery-1.7.2.js" ></script>
</head>
<body>
<form id="basic_compensation_add" name="basic_compensation_add" method="post" action="basicCompensation!update">
  <table width="800" border="1" align="center" cellpadding="0" cellspacing="0">
    <tr>
      <th colspan="3" scope="col">修改基本薪资信息</th>
    </tr>
    <tr>
      <td width="100">部门</td>
      <td width="500">
        <select name="departmentID" id="departmentID">
          <option value="0">请选择</option>
          <s:iterator value="departmentList" var="list">
          	<s:if test="basicCompensation.departmentID==departmentID">
          	  <option value='<s:property value="departmentID"/>' selected="selected"><s:property value="departmentName"/></option>
          	</s:if>
          	<s:else>
          	  <option value='<s:property value="departmentID"/>'><s:property value="departmentName"/></option>
          	</s:else>
          </s:iterator>
        </select></td>
      <td width="200">选择部门</td>
    </tr>
    <tr>
      <td>职位</td>
      <td>
        <select name="positionID" id="positionID">
          <option value="0">请选择</option>
          <s:iterator value="positionList" var="list">
          	<s:if test="basicCompensation.positionID==positionID">
          	  <option value='<s:property value="positionID"/>' selected="selected"><s:property value="positionName"/></option>
          	</s:if>
          	<s:else>
          	  <option value='<s:property value="positionID"/>'><s:property value="positionName"/></option>
          	</s:else>
          </s:iterator>
        </select></td>
      <td>选择职位</td>
    </tr>
    <tr>
      <td>基本薪资</td>
      <td><input name="basicCompensationAmount" type="text" id="basicCompensationAmount" size="50" maxlength="50" value='<s:property value="basicCompensation.basicCompensationAmount"/>'/></td>
      <td>此部门-职位的基本薪资</td>
    </tr>
    <tr>
      <td colspan="3">
      	<input name="basicCompensationID" type="hidden" id="basicCompensationID" value='<s:property value="basicCompensation.basicCompensationID"/>'/>
        <input name="submit" type="submit" id="submit" value="修改" />
		<input name="reset" type="reset" id="reset" value="重置" />
	  </td>
    </tr>
  </table>
</form>
<script type="text/javascript">
		$(function(){
    		$("#submit").click(function(){
     			if($("#departmentID").find("option:selected").index()==0){
      				alert("请选择员工所属部门!");
      				$("#departmentID").focus();
     				return false;
     			}
     			if($("#positionID").find("option:selected").index()==0){
      				alert("请分配职位!");
      				$("#positionID").focus();
     				return false;
     			}
     			if($("#basicCompensationAmount").val()==""){
      				alert("请输入基本薪资!");
      				$("#basicCompensationAmount").focus();
     				return false;
     			}
    		});
    		$("#departmentID").change(function(){
     			var departID= $("#departmentID").find("option:selected").val();
				if ( departID == 0){
					$("#positionID").empty();
					$("<option value='0'>请选择</option>").appendTo($("#positionID"));
				} else {
					$.ajax({
						url : "ajaxJson!listPosition",
						type: "post",
						data: "departmentID=" + departID,
						dataType: "json",
						success: function(data){
							$("#positionID").empty();
							var obj = eval("("+data.position+")");
							$("<option value='0'>请选择</option>").appendTo($("#positionID"));
							for(var i = 0; i < obj.position.length; i++){
								$("<option value='"+obj.position[i].positionID+"'>"+obj.position[i].positionName+"</option>").appendTo($("#positionID"));
							}
						},
						error: function(){
      						alert("出错了，请稍后再试！");
     					}
					});
				}
    		});
  		});
</script>
</body>
</html>
